package view;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
/**
 * this class is Graphic user interface of create new employee for Human Resources Employee which extends AbstractGUI
 * @author Gili
 *
 */
public class HRcreateNewEmployeeGui extends AbstractGUI {

	private JButton registerBut = null;
	private JButton backB = null;
	
	private JLabel lblUserName = null;
    private JLabel lblwarningMessage = null;
    private JLabel lbAge = null;
	private JLabel lblId = null;
	private JLabel lbphone = null;
	private JLabel lbArea = null;
	private JLabel lbLastName = null;
	private JLabel lbEmail = null;
	private JLabel lblPosition;
	private JLabel lblPassword;
	private JLabel lblUserName_1;
	
	private JTextField textFieldName = null;
	private JTextField textFieldId = null;
	private JTextField textFieldAge = null;
	private JTextField textFieldPhone = null;
	private JTextField textFieldLastName = null;
	private JTextField textFieldEmail = null;
	private JTextField password;
	private JTextField userNameTxt;
	
	private JComboBox<String> AreaC;
	private JComboBox<String> positionC;
	
	private Font myFont ;
	

	public HRcreateNewEmployeeGui(){
		
		myFont = new Font("Serif",Font.BOLD,17);
		getContentPane().setLayout(null);
		getContentPane().add(getLblwarningMessage("Error Message"));
		getContentPane().add(getregisterBut());
		getContentPane().add(getlblUserName());
		getContentPane().add(getlblId());
		getContentPane().add(getlbAge());
		getContentPane().add(getlbphone());
		getContentPane().add(gettextFieldId());
		getContentPane().add(getTextFieldName());
		getContentPane().add(getTextFieldAge());
		getContentPane().add(getTextFieldPhone());
		getContentPane().add(getAreaC());
		getContentPane().add(getlbArea());
		getContentPane().add(getbackButton());
		getContentPane().add(getLbEmail());
		getContentPane().add(getLbLastName());
		getContentPane().add(getTextFieldEmail());
		getContentPane().add(getTextFieldLastName());
		//getContentPane().add(getPositionC());
		//getContentPane().add(getPassword());
		getContentPane().setBackground(Color.pink);
		
		lblPosition = new JLabel("Position:");
		lblPosition.setBounds(30, 291, 80, 14);
		getContentPane().add(lblPosition);
		
		lblPassword = new JLabel("Password:");
		lblPassword.setBounds(30, 359, 90, 14);
		getContentPane().add(lblPassword);
		
		password = new JTextField();
		password.setBounds(120, 353, 130, 20);
		getContentPane().add(password);
		password.setColumns(10);
		
		positionC = new JComboBox<String>();
		positionC.setBounds(120, 288, 128, 20);
		getContentPane().add(positionC);
		positionC.addItem("");
		positionC.addItem("Marketer");
		positionC.addItem("Marketing Manager");
		positionC.addItem("Salesman");
		positionC.addItem("Customer Relations");
		positionC.addItem("Human Resources");
		positionC.setEditable(false);
		getContentPane().add(getLblUserName_1());
		
		userNameTxt = new JTextField();
		userNameTxt.setBounds(120, 319, 130, 20);
		getContentPane().add(userNameTxt);
		userNameTxt.setColumns(10);
		
		this.setTitle("ccrm/Register New Employee");
		this.setBounds(500, 200, 450, 470);
	//	this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		this.setVisible(true);
		this.setResizable(false);
	}
	
	public JTextField getUserNameTxt() {
		return userNameTxt;
	}
	
	public JComboBox<String> getPositionC() {
		return positionC;
	}


	public void setPositionC(JComboBox<String> positionC) {
		this.positionC = positionC;
	}


	public void setRegisterBut(JButton registerBut) {
		this.registerBut = registerBut;
	}


	public void setTextFieldName(JTextField textFieldName) {
		this.textFieldName = textFieldName;
	}


	public void setTextFieldId(JTextField textFieldId) {
		this.textFieldId = textFieldId;
	}


	public void setTextFieldAge(JTextField textFieldAge) {
		this.textFieldAge = textFieldAge;
	}


	public void setTextFieldPhone(JTextField textFieldPhone) {
		this.textFieldPhone = textFieldPhone;
	}


	public void setTextFieldLastName(JTextField textFieldLastName) {
		this.textFieldLastName = textFieldLastName;
	}


	public void setTextFieldEmail(JTextField textFieldEmail) {
		this.textFieldEmail = textFieldEmail;
	}


	public void setPassword(JTextField password) {
		this.password = password;
	}


	public JButton getRegisterBut() {
		return registerBut;
	}


	public JLabel getLblUserName() {
		return lblUserName;
	}


	public JLabel getLbphone() {
		return lbphone;
	}


	public JTextField getTextFieldId() {
		return textFieldId;
	}


	public Font getMyFont() {
		return myFont;
	}

	public JTextField getPassword() {
		return password;
	}


	public JLabel getLblwarningMessage(String msg) {
		if(lblwarningMessage == null){
			lblwarningMessage = new JLabel(msg);
			lblwarningMessage.setForeground(Color.RED);
			lblwarningMessage.setBounds(10, 20, 200, 30);
			lblwarningMessage.setVisible(false);
		}
		else{
			lblwarningMessage.setText(msg);
			lblwarningMessage.setForeground(Color.RED);
			lblwarningMessage.setBounds(10, 20, 200, 30);
			lblwarningMessage.setVisible(false);
		}
		return lblwarningMessage;
	}
	public void setWarningMessageVisibleTrue() {
		lblwarningMessage.setVisible(true);	
	}
	
	public void setWarningMessageVisibleTrue(String st) {
		lblwarningMessage.setText(st);
		lblwarningMessage.setForeground(Color.RED);
		lblwarningMessage.setBounds(10, 20, 200, 30);
		lblwarningMessage.setVisible(true);	
	}

	public JButton getregisterBut() {
		
		if(registerBut == null ) {
			registerBut = new JButton("Register");
			registerBut.setBounds(270, 395, 120, 20);
		}
		return registerBut;
	}
	
   public JButton getbackButton() {
		
		if(backB == null ) {
			backB = new JButton("back");
			backB.setBounds(86, 395, 120, 20);
		}
		return backB;
	}
   
	public JLabel getlblId() {
		if(lblId == null) {
			lblId = new JLabel("id:");
			lblId.setBounds(30, 70, 90, 20);
			//lblId.setFont(myFont);
		}
		return lblId;
	}

	public JLabel getlblUserName() {
		if(lblUserName == null){
			lblUserName = new JLabel("Firts Name:");
			lblUserName.setBounds(30, 100, 120, 20);
			//lblUserName.setFont(myFont);
		}
		return lblUserName;
	}
	public JLabel getlbAge() {
		if(lbAge == null){
			lbAge = new JLabel("Age:");
			lbAge.setBounds(30, 160, 90, 20);
			//lbAge.setFont(myFont);
		}
		return lbAge;
	}
	public JLabel getlbphone() {
		if(lbphone == null){
			lbphone = new JLabel("phone :");
			lbphone.setBounds(30, 190, 90, 20);
			//lbphone.setFont(myFont);
		}
		return lbphone;
	}
	
	public JLabel getlbArea() {
		if(lbArea == null){
			lbArea = new JLabel("Area :");
			lbArea.setBounds(30, 253, 90, 20);
			//lbArea.setFont(myFont);
		}
		return lbArea;
	}
	
	public JTextField gettextFieldId() {
		if(textFieldId == null) {
			textFieldId = new JTextField();
			textFieldId.setBounds(120, 73, 130, 20);
			textFieldId.setColumns(10);
		}
		return textFieldId;
	}

	public JTextField getTextFieldName() {
		if(textFieldName == null) {
			textFieldName = new JTextField();
			textFieldName.setBounds(120, 103, 130, 20);
			textFieldName.setColumns(10);
		}
		return textFieldName;
	}
	
	public JTextField getTextFieldAge() {
		if(textFieldAge == null) {
			textFieldAge = new JTextField();
			textFieldAge.setBounds(120, 163, 130, 20);
			textFieldAge.setColumns(10);
		}
		return textFieldAge;
	}
	
	public JTextField getTextFieldPhone() {
		if(textFieldPhone == null) {
			textFieldPhone = new JTextField();
			textFieldPhone.setBounds(120, 193, 130, 20);
			textFieldPhone.setColumns(10);
		}
		return textFieldPhone;
	}

	public void ClearText(){
		textFieldPhone.setText("");
		textFieldAge.setText("");
		textFieldName.setText("");
		textFieldId.setText("");
		textFieldEmail.setText("");
		textFieldLastName.setText("");
		password.setText("");
		userNameTxt.setText("");
		positionC.setSelectedIndex(0);
		AreaC.setSelectedIndex(0);
	}

	public String getTextUserName() {
		return textFieldName.getText();
	}
	
	public String getTextphone() {
		
		return textFieldPhone.getText();
	}
	public String getTextId() {
		
		return textFieldId.getText();
	}
	
	public int getTextAge() {
		int foo;
		if(textFieldAge.getText().equals(""))
			return 0;
	try{
	   foo = Integer.parseInt(textFieldAge.getText()); 
	}
       catch(NumberFormatException e) { 
             return -1; 
      }
		return foo;
	}
	
	public String getTextAgeTe() {
		
		return textFieldAge.getText();
	}
	
	public String getTextEmail() {
		
		return textFieldEmail.getText();
	}
	public String getTextLastName() {
		
		return textFieldLastName.getText();
	}
	public JComboBox<String> getAreaC() {
		if(AreaC == null){
			AreaC = new JComboBox<String>();
			AreaC.setBounds(120, 253, 130, 20);
		}
		return AreaC;
	}

	public JLabel getLbLastName() {
		if(lbLastName == null) {
			lbLastName = new JLabel("Last Name:");
			lbLastName.setBounds(30, 130, 120, 20);
			//lbLastName.setFont(myFont);
		}

		return lbLastName;
	}



	public JLabel getLbEmail() {
		if(lbEmail == null) {
			lbEmail = new JLabel("Email:");
			lbEmail.setBounds(30, 220, 90, 20);
			//lbEmail.setFont(myFont);
		}
		return lbEmail;
	}



	public JTextField getTextFieldLastName() {
		if(textFieldLastName == null) {
			textFieldLastName = new JTextField();
			textFieldLastName.setBounds(120, 133, 130, 20);
			textFieldLastName.setColumns(10);
		}
		return textFieldLastName;
	}



	public JTextField getTextFieldEmail() {
		if(textFieldEmail == null) {
			textFieldEmail = new JTextField();
			textFieldEmail.setBounds(120, 223, 130, 20);
			textFieldEmail.setColumns(10);
		}
		return textFieldEmail;
	}


	public void setAreaC(JComboBox<String> areaC) {
		AreaC = areaC;
	}
	
	public void undisplayWarningMessage() {
		lblwarningMessage.setVisible(false);
		
	}

	
	public void addRegisterActionListener(ActionListener listener){
		registerBut.addActionListener(listener);
	}
	
	public void addAreaActionListener(ItemListener listener){
		AreaC.addItemListener(listener);
	}

	
	public void addbackBActionListener(ActionListener listener){
		backB.addActionListener(listener);
	}
	private JLabel getLblUserName_1() {
		if (lblUserName_1 == null) {
			lblUserName_1 = new JLabel("User Name:");
			lblUserName_1.setBounds(30, 323, 80, 14);
		}
		return lblUserName_1;
	}
}
